package com.daotingli.backendprograms.Controller.Admin.AuthorBook;

import com.daotingli.backendprograms.Service.Admin.AuthorBook.AuthorBookService;
import com.daotingli.backendprograms.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class AuthorBookController {
    @Autowired
    private AuthorBookService authorBookService;

    /**
     * 获取全部数据 数据信息
     */
    @RequestMapping(path = "/admin/authorBook/getAll",method = RequestMethod.POST)
    public Result getAllAuthorBooks()
    {
        return authorBookService.getAllAuthorBooks();
    }

    /**
     * 获取所有作者信息
     */
    @RequestMapping(path = "/admin/authorBook/author",method = RequestMethod.POST)
    public Result getAllAuthors()
    {
        return authorBookService.getAllAuthors();
    }
    /**
     * 获取未被删除的书籍信息
     */
    @RequestMapping(path = "/admin/authorBook/book",method = RequestMethod.POST)
    public Result getAllBooks(){
        return authorBookService.getAllBooks();
    }
    /**
     * 获取所有被删除的书籍信息
     */
    @RequestMapping(path = "/admin/authorBook/DeleteBook",method = RequestMethod.POST)
    public Result getAllNoDeleteBooks(){
        return authorBookService.getAllNoDeleteBooks();
    }
    /**
     * 添加书籍信息
     */
    @RequestMapping(path = "/admin/authorBook/add",
            method = RequestMethod.POST,
            params = {"bookname","author_id","book_state"})
    public Result addAuthorBook(@RequestParam("bookname") String bookname,
                                @RequestParam("author_id") String author_id,
                                @RequestParam("book_state") String book_state){
        return authorBookService.addAuthorBook(bookname,author_id,book_state);
    }

    /**
     * 删除书籍
     * @param id
     * @return
     */
    @RequestMapping(path = "/admin/authorBook/delete",method = RequestMethod.POST,params = {"id"})
    public Result deleteAuthorBook(@RequestParam("id") Integer id)
    {
        return authorBookService.deleteAuthorBook(id);
    }
    /**
     * 修改书籍信息
     */
    @RequestMapping(path = "/admin/authorBook/update",
            method = RequestMethod.POST,
            params = {"id","bookname","author_id","book_state"})
    public Result updateAuthorBook(@RequestParam("id") Integer id,
                                   @RequestParam("bookname") String bookname,
                                   @RequestParam("author_id") String author_id,
                                   @RequestParam("book_state") String book_state){
        return authorBookService.updateAuthorBook(id,bookname,author_id,book_state);
    }

}
